<?php

use App\Http\Middleware\RequestMini;
use App\Http\Middleware\ResponseMini;
use App\Http\Middleware\VerifyMiniToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/


Route::any('/{Module}/{Action}/{Function}', function ($Module, $Action, $Function) {
    $controllerName = implode('\\', [
        env('APP_NAME_SPACE'),
        'Modules',
        ucfirst($Module),
        'Apis',
        ucfirst($Action)
    ]);
    return (new $controllerName)->$Function(Request::capture());
});

//自定义路由
Route::middleware([RequestMini::class, VerifyMiniToken::class, ResponseMini::class])->group(function () {
    $class = implode('\\', [
        env('APP_NAME_SPACE'),
        'Modules',
        'ApiRoute',
    ]);
    if (class_exists($class)) call_user_func([$class, 'init']);
});

Route::middleware([RequestMini::class, ResponseMini::class])->group(function () {
    $class = implode('\\', [
        env('APP_NAME_SPACE'),
        'Modules',
        'ApiRoute',
    ]);
    if (class_exists($class)) call_user_func([$class, 'initWithoutToken']);
});

